package com.example.backend.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class FileUploadConfig implements WebMvcConfigurer {
    // 浏览器端访问路径
    @Value("${project.file.access-path}")
    private String url;

    // 文件保存路径
    //    HTTP/file/
    @Value("${spring.servlet.multipart.location}")
    private String filePath;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(this.url)
                .addResourceLocations("file:" + this.filePath);
    }
}
